trigger trg_setLocationStatus on Location_Booking_Information__c (after insert, before update) 
{
    //Map<Id, Location_Booking_Information__c> mapLocationBooking
    Map<Id,string> locationIdMap  = new Map<Id,string>();
    //Map<Id,string> bookingLocationStatusMap = new Map<Id,string>();
    Map<Id,Location_Booking_Information__c> bookingLocationStatusMap = new Map<Id,Location_Booking_Information__c>();
    List<Location__c> locationUpdateList = new List<Location__c>();
    
    if(Trigger.isInsert)
    {
        for(Location_Booking_Information__c tempLocationBooking :trigger.New)
        {
             if(tempLocationBooking.License_Booking_Status__c == 'Booked' || tempLocationBooking.License_Booking_Status__c == 'Released')    
             {
                 locationIdMap.put(tempLocationBooking.Id,tempLocationBooking.Location__c);   
                 //bookingLocationStatusMap.put(tempLocationBooking.Location__c,tempLocationBooking.License_Booking_Status__c);
                 bookingLocationStatusMap.put(tempLocationBooking.Id,tempLocationBooking);
                 
                 System.debug('The Insertion Time Location Object Checked=> '+locationIdMap.size() + ' & The Booking Location => '+ bookingLocationStatusMap.size());
                 
             }   
        }
    }
    
    if(Trigger.isUpdate)
    {
        for(Location_Booking_Information__c tempLocationBooking :trigger.New)
        {
            if(Trigger.oldMap.get(tempLocationBooking.Id).License_Booking_Status__c != tempLocationBooking.License_Booking_Status__c)
            {
                if(tempLocationBooking.License_Booking_Status__c == 'Booked' || tempLocationBooking.License_Booking_Status__c == 'Released')    
                {
                    locationIdMap.put(tempLocationBooking.Id,tempLocationBooking.Location__c);   
                    //bookingLocationStatusMap.put(tempLocationBooking.Location__c,tempLocationBooking.License_Booking_Status__c);
                    bookingLocationStatusMap.put(tempLocationBooking.Id,tempLocationBooking);
                }
            }
             
        }
    
    }
    System.debug('The Booking Location Keys => '+ bookingLocationStatusMap.keyset());
    if(locationIdMap.size() > 0)
    {
        //Query the location Object....
        for(Location__c locationObject : [select Id,Location_Status__c,Location_Booked_Information_Flag__c from Location__c where Id IN :locationIdMap.values()])
        {
            //if(locationObject.Location_Status__c == 'Leased' && locationObject.)    
            //{
                for(ID bookingRecordId : locationIdMap.keyset())    
                {
                    if(bookingLocationStatusMap.get(bookingRecordId) != null)
                    {
                        if(bookingLocationStatusMap.get(bookingRecordId).License_Booking_Status__c == 'Booked')
                            locationObject.Location_Booked_Information_Flag__c = true;
                        else if(bookingLocationStatusMap.get(bookingRecordId).License_Booking_Status__c == 'Released')    
                            locationObject.Location_Booked_Information_Flag__c = false;    
                       
                        //Break the Loop...
                        break;
                    }
            
                }  
            
            /*}
            else
            {
               for(ID bookingRecordId : locationIdMap.keyset())    
               {
                    bookingLocationStatusMap.get(bookingRecordId).Location__c.adderror('Please Select the Leased Location'); 
                    
                    break;
               }     
            }*/
            
            //Adding in the Location Update List...
            locationUpdateList.add(locationObject);
        
        }
        System.debug('The Insertion Time locationUpdateList => '+locationUpdateList.size());
        
        //Now update the objects...
        if(locationUpdateList.size() > 0)
            update locationUpdateList;
        
    }
    
}